{include file="common/mainHead"/}
<style>
    .layui-table .layui-form-checkbox[lay-skin=primary]{margin:0;}
</style>
<div style="margin: 15px;" class="fadeInUp animated">
    <blockquote class="layui-elem-quote">
        <form class="layui-form" style="float:left;" action="" method="post">
            <div class="layui-form-item" style="margin:0;">
                <div class="layui-input-inline">
                    <input type="text" name="key" id="key" placeholder="{:lang('pleaseEnter')}关键字！" autocomplete="off" class="layui-input">
                </div>
                <div class="layui-form-mid layui-word-aux" style="padding:0;">
                    <button type="button" id="search"  class="layui-btn"><i class="fa fa-search" aria-hidden="true"></i> 查询</button>
                    <a href="{:url('index',['catid'=>input('catid')])}" class="layui-btn">显示全部</a>
                </div>
            </div>
        </form>

        <a href="{:url('Category/index')}" class="layui-btn layui-btn-normal" style="float:right;"><i class="fa fa-undo" aria-hidden="true"></i>返回栏目</a>
        <a href="{:url('add',array('catid'=>input('catid')))}" class="layui-btn" style="float:right;margin-right: 15px;"><i class="fa fa-plus" aria-hidden="true"></i>{:lang('add')}</a>
        <div style="clear: both;"></div>
    </blockquote>
    <fieldset class="layui-elem-field ">
        <legend>{:lang('list')}</legend>
        <div class="layui-field-box table-responsive">
            <form class="layui-form layui-form-pane">
                <div class="layui-form">
                <table class="layui-table table-hover">
                    <thead>
                    <tr>
                        <th><input type="checkbox" name="" lay-skin="primary" lay-filter="allChoose"></th>
                        <th>{:lang('order')}</th>
                        <th>{:lang('id')}</th>
                        <th>{:lang('title')}</th>
                        <th>{:lang('hit')}</th>
                        <th>{:lang('add')}{:lang('time')}</th>
                        <th>操作</th>
                    </tr>
                    </thead>
                    <!--内容容器-->
                    <tbody id="con">
                    <tr>
                    </tr>
                    </tbody>
                    <tfoot>
                    <tr>
                        <td colspan="2">
                            <button type="button" class="layui-btn layui-btn-small layui-btn-danger" onclick="return delall();">{:lang('del')}</button>
                            <button type="button" class="layui-btn  layui-btn-small" lay-submit="" lay-filter="sort">{:lang('order')}</button>
                        </td>
                        <td colspan="7">
                            <!--分页容器-->
                            <div id="paged" style="text-align: right"></div>
                        </td>
                    </tr>
                    </tfoot>
                </table>
                </div>
            </form>
        </div>
    </fieldset>
</div>

<!--模板-->
<script type="text/html" id="conTemp">
    {{# layui.each(d.list, function(index, item){ }}
    <tr>
        <td>
            <input type="checkbox" name="ids[]" value="{{ item.id }}" lay-skin="primary">
        </td>
        <td><input name='listorders[{{ item.id }}]' type='text' size='3' value='{{ item.listorder }}' class='list_order'></td>
        <td>{{ item.id }}</td>
        <td style="{{item.title_style}}">{{ item.title }}</td>
        <td>{{ item.hits}}</td>
        <td>{{ item.createtime}}</td>
        <td>
            <a href="{:url('edit')}?id={{item.id}}&catid={{item.catid}}" class="layui-btn layui-btn-mini">编辑</a>
            <a href="javascript:;" onclick="return del({{item.id}})" data-id="1" data-opt="del" class="layui-btn layui-btn-danger layui-btn-mini">删除</a>
        </td>
    </tr>
    {{# }); }}
</script>
{include file="common/mainFoot"/}
<script>
    layui.config({
        base: '__ADMIN__/js/'
    }).use(['paging', 'code','icheck','layer','form'], function() {
        var paging = layui.paging(),form = layui.form();layer = parent.layer === undefined ? layui.layer : parent.layer;
        paging.init({
            url: "{:url('index')}", //地址
            elem: '#con', //内容容器
            params: {
                'catid':"{:input('catid')}"
            }, //发送到服务端的参数
            tempElem: '#conTemp', //模块容器
            pageConfig: { //分页参数配置
                elem: '#paged', //分页容器
                pageSize: 15 //分页大小
            },
            success: function() { //渲染成功的回调
                //alert('渲染成功');
            },
            fail: function(msg) { //获取数据失败的回调
                //alert('获取数据失败')
            },
            complate: function() { //完成的回调
                //alert('处理完成');
                form.render();
            }
        });
        form.on('submit(sort)', function(data){
            $.post("{:url('listorder',array('catid'=>input('catid')))}",data.field,function(res){
                if(res.code > 0){
                    layer.msg(res.msg,{time:1000,icon:1},function(){
                        window.location.href = res.url;
                    });
                }else{
                    layer.msg(res.msg,{time:1000,icon:2});
                }
            })
        });
        var form = layui.form(),layer = layui.layer;
        //全选
        form.on('checkbox(allChoose)', function(data){
            var child = $(data.elem).parents('table').find('tbody input[type="checkbox"]');
            child.each(function(index, item){
                item.checked = data.elem.checked;
            });
            form.render('checkbox');
        });
        //搜索
        $('#search').on('click', function() {
            var $this = $(this);
            var key = $('#key').val();
            if($.trim(key)=='') {
                layer.msg('{:lang('pleaseEnter')}关键字！');
                return;
            }
            //调用get方法获取数据
            paging.get({
                key: key //获取输入的关键字。
            });
        });
    });

    function del(id) {
        layer.confirm('你确定要删除吗？', {icon: 3}, function (index) {
            layer.close(index);
            window.location.href = "{:url('listDel',['catid'=>input('catid')])}?id=" + id;
        });
    }
    function delall() {
        var ids = '';
        $('input[name*=\'ids\']:checked').each(function (){
            ids += $(this).val() + ',';
        });
        layer.confirm('确认要删除选中信息吗？', {icon: 3}, function(index){
            $.post("{:url('delAll')}", {ids:ids,catid:"{:input('catid')}"}, function (result) {

                    window.location.href = result.url;

            });
            layer.close(index);
        })

    }
</script>